package models;

import play.*;
import play.db.jpa.*;
import play.libs.Codec;

import javax.persistence.*;
import java.util.*;

@Entity
public class Offer extends Model  implements Comparable<Offer>{
	
	public boolean active;
	public boolean premium;
	@Lob
	public String description;
	public Date startDate;
	public Date endDate;
	public String city;
	public String street;
	public String streetNumber;
	public int zipcode;
	public int size;
	public float price;
	
	@ManyToOne
	public Event event;
	
	@ManyToOne
	public User user;
	
	public Blob picture;
	
	/* minimal constructor
	 * event sets corresponding event to the offer
	 * user sets corresponding user to the offer
	 */
	
	public Offer(Event event, User user){
		this.event=event;
		this.user=user;
	}

	@Override
	public int compareTo(Offer o) {
		if (o.startDate.getTime()<this.startDate.getTime())
			return 1;
		else if(o.startDate.getTime()>this.startDate.getTime())
			return -1;
		return 0;
	}
	
	public String toString(){
		return city+" "+street;
	}
	
	public boolean isCommercial(){
		if (user instanceof CommercialOfferer){
			return true;
		}
		return false;

	}
	
	
}
